package cn.xorange.commons.security.entity;

import cn.xorange.commons.security.constants.HeaderConstants;
import cn.xorange.commons.security.constants.SecurityConstants;
import cn.xorange.commons.security.enums.SysType;
import cn.xorange.commons.utils.lang.ObjectUtils;
import cn.xorange.commons.utils.lang.StringUtils;
import lombok.Getter;

/**
 * @author : yangjian
 * @date : 2023/12/20
 */
@Getter
public class ClaimsInfo {

    private final String sysType;   //enum  sys,app,web,(api)
    private final String loginType; //enum  pw,wx,wxScan,api
    private final String source;    //tenantId, mp...
    private final String tokenId;
    private Long tenantId;
    private Long userId;
    private String username;
    private boolean isAdmin;

    public ClaimsInfo(String sysType, String loginType, String source, String tokenId){
        this.sysType = sysType;
        this.loginType = loginType;
        this.source = source;
        this.tokenId = tokenId;
        if(SysType.SYS.type().equals(sysType)){
            this.tenantId = ObjectUtils.toLong(source);
        }
    }

    public String tokenKey(){
        return StringUtils.format("{}:{}:{}", sysType, source, tokenId);
    }

    // 签发对象
    public String audience(){
        return sysType;
    }

    public void setUserId(Long userId){
        this.userId = userId;
    }
    public void setUsername(String username){
        this.username = username;
    }
    public void setIsAdmin(boolean isAdmin){
        this.isAdmin = isAdmin;
    }

}
